<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 
<jsp:include page="/common/commonjs.jsp"></jsp:include>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>家庭管理管理</title>
</head>
<body>
	<script type="text/javascript">
	Ext.onReady(function(){
		Ext.QuickTips.init();
		Ext.form.Field.prototype.msgTarget = 'side';
		Ext.apply(Ext.form.VTypes, {
	    password : function(val, field) {
	        if (field.initialPassField) {
	            var pwd = Ext.getCmp(field.initialPassField);
	            return (val == pwd.getValue());
	        }
	        return true;
	    },
	    passwordText : '密码不匹配'
	});
		var	passModifyForm = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,  
      	bodyStyle:'padding:5px;',
        labelAlign: 'right',
        buttonAlign :'center',
        defaults: {width: 230},
        defaultType: 'textfield',
        items: [{
                fieldLabel: '原密码',
                name: 'oldpass',
                id:'oldpass',
                inputType:'password',
                allowBlank:false
            },{
                fieldLabel: '新密码',
                name: 'newpass',
                id:'newpass',
                inputType:'password',
                allowBlank:false
            },{
                fieldLabel: '确认密码',
                name: 'newpassconfirm',
                id:'newpassconfirm',
                inputType:'password',
                allowBlank:false,
                vtype: 'password',
                initialPassField: 'newpass'
            }
        ],

        buttons: [{
            text: '确认修改',
            handler:confirm

        },{
            text: '重置',
          	handler:reset

        }]
    });

	 var win = new Ext.Window({
		title: '密码修改',
		closable:false,
        width: 380,
        height:180,
        layout: 'fit',
        plain:true,
        items:passModifyForm
	 }).show();
	 Ext.getCmp("newpassconfirm").on('specialkey',function(){
		var key = Ext.EventObject.getKey();
		if (key == 13){
			confirm();
		}
	 });
	//点击确认修改	
	function confirm(){
		var v_pass = Ext.getDom("oldpass").value;
		var v_newpass = Ext.getDom("newpassconfirm").value;
		if(passModifyForm.getForm().isValid()){
			//检查原密码是否正确
			Ext.Ajax.request({
				url:"selfinfo!modify.action",
				success:function(obj){				
					var result = obj.responseText;	
					if(result == 'passerror'){
						Ext.Msg.alert('提示','原密码输入有误,请检查!',function(){
								reset();
							});
					}else if(result == "success"){
						Ext.Msg.alert('提示','密码修改成功,请退出后用新密码登录',function(){
								reset();
							});
					}else{
						Ext.Msg.alert('提示','密码修改失败!',function(){
							    reset();
							});
					}
				
				},
			params:{passwd:v_pass,newpass:v_newpass}
			});
		}
	}	
	//点击重置后
	function reset(){
		passModifyForm.getForm().reset();
	}
	}
		
	);
		
	</script>
</body>
</html>